package com.example.flshtarvel.mapper;

import com.example.flshtarvel.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

//指定操作数据库mapper
@Mapper
public interface UserMapper {
    //添加用户
    @Insert("insert into user (user_id,user_name,password,role,time) values(#{userId},#{userName},#{password},#{role},#{time})")
    public int insertUser(User user);

    //查询用户 通过id
    @Select("select * from user where user_id=#{userId}")
    public User selectUserById(String userId);

    //查询用户  通过用户名
    @Select("select * from user where user_name=#{userName}")
    public User selectUserByName(String userName);

    //查询用户是否存在，通过用户名和密码
    @Select("select * from user where user_name=#{userName} and password=#{password}")
    public User doLogin(User user);


    //查询所有用户
    @Select("select * from user limit #{offset},#{size}")
    public List<User> selectAllUser(int offset, int size);

    //查询所有用户数据记录数
    @Select("select count(*) from user")
    public int selectUserCount();

    //删除用户
    @Delete("delete from user where user_id= #{userId}")
    public int deleteUser(String userId);

    //更新用户
    @Update("update user set user_name=#{userName},password=#{password},role=#{role},time=#{time} where user_id=#{userId}")
    public int updateUser(User user);
}
